package com.xingdata.jjxc.utils;

import java.security.MessageDigest;

public class Code {
	// 5. MD5加码 32位可见
	public static String CodeMD5(String inStr) {
		if (inStr == null) {
			return "";
		}
		MessageDigest md5 = null;
		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (Exception e) {
			System.out.println(e.toString());
			e.printStackTrace();
			return "";
		}
		char[] charArray = inStr.toCharArray();
		byte[] byteArray = new byte[charArray.length];

		for (int i = 0; i < charArray.length; i++)
			byteArray[i] = (byte) charArray[i];

		byte[] md5Bytes = md5.digest(byteArray);
		StringBuffer hexValue = new StringBuffer();

		for (int i = 0; i < md5Bytes.length; i++) {
			int val = ((int) md5Bytes[i]) & 0xff;
			if (val < 16)
				hexValue.append("0");
			hexValue.append(Integer.toHexString(val));
		}
		return hexValue.toString();
	}

	// double MD5
	public static String doubleMD5(String str) {
		return Code.CodeMD5(Code.CodeMD5(str).toUpperCase()).toUpperCase();
	}

	/**
	 * 上传视频文件Token
	 * 
	 * @param phone
	 * @param psw
	 * @param userID
	 * @return
	 */
	public static String accessToken(String phone, String psw, String userID) {
		return CodeMD5(
				phone + CodeMD5(CodeMD5(psw).toUpperCase()).toUpperCase()
						+ userID).toUpperCase();
		
		
		

	}

	/**
	 * 组装accessToken
	 */
	public static String accessToken() {
		return CodeMD5(
				SystemInfo.getUserInfo().getMobile()
						+ SystemInfo.getUserInfo().getPw()
						+ SystemInfo.getUserInfo().getUserid()).toUpperCase();
	}
}
